# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=('libmetalink' 'libmetalink-devel')
pkgver=0.1.3
pkgrel=2
pkgdesc="Metalink XML parser library"
groups=('libraries')
arch=('i686' 'x86_64')
license=('MIT')
url="https://launchpad.net/libmetalink"
depends=('msys2-runtime' 'libexpat' 'sh' 'libxml2')
makedepends=('libexpat-devel' 'pkg-config')
source=(${url}/trunk/packagingfix/+download/${pkgname}-${pkgver}.tar.xz
        libmetalink-0.1.2-msys2.patch)
sha256sums=('86312620c5b64c694b91f9cc355eabbd358fa92195b3e99517504076bf9fe33a'
            'b69e0aa0de75888653a71fcc52767cda295443943e6712c720b82877f7cb25a6')

prepare() {
  cd "${srcdir}/${pkgname}-${pkgver}"

  patch -p1 -i ${srcdir}/libmetalink-0.1.2-msys2.patch
  autoreconf -fi
}

build() {
  cd "${srcdir}/${pkgname}-${pkgver}"

  ./configure \
    --prefix=/usr \
    --build=${CHOST} \
    --enable-shared \
    --enable-static

  make
  make DESTDIR=${srcdir}/dest install
}

package_libmetalink() {
  groups=('libraries')

  mkdir -p ${pkgdir}/usr
  cp -rf ${srcdir}/dest/usr/bin ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/share ${pkgdir}/usr/
}

package_libmetalink-devel() {
  pkgdesc="libmetalink headers and libraries"
  groups=('development')
  options=('staticlibs')
  depends=("libmetalink=${pkgver}" 'libexpat-devel')

  mkdir -p ${pkgdir}/usr
  cp -rf ${srcdir}/dest/usr/include ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/lib ${pkgdir}/usr/
}
